/* eslint-disable no-negated-condition */
/* eslint-disable react/no-direct-mutation-state */
import React from 'react';
import PropTypes from 'prop-types';
import routes from './routes';
import cloneDeep from 'lodash/cloneDeep';
import {Popconfirm, Table, Button, Form, Row, Col, Card, Spin, message as msg, Modal} from 'antd';
import {getDetail, getKdClaimDetails, getDealerSaleInformations, getKDClaimDetail, getCarriers} from './api';
import {FORM_OPTIONS, TABLE, FIXED_COLUMN_WIDTH} from '../constants';
import Return from '../common/Return';
import FormItem from 'antd/lib/form/FormItem';
import {hasPermissions, uuid, getUrl} from './utils';
import {formatAmount} from '../utils';
import {PERMISSION, invoiceSource} from './constants';
import {newOrUpdateOrderValidator, saleOrderValidator} from './validator';
import {injectIntl, language} from './intl';
import WrappedSelect from '../common/WrappedSelect';
import DealerSelectPanel from '../common/DealerSelect/SelectEdit';
import TextInput from 'Shared/components/TextInput';
import InputAmount from '../common/InputAmount';
import SearchInput from 'Shared/components/SearchInput';
import BankSelectPanel from './BankSelectPanel';
import SaleOrderPanel from './SaleOrderPanel';
import SaleOrderDetailPanel from './SaleOrderDetailPanel';
import KdClaimPanel from './KdClaimPanel';
import LocalizeInputNumber from '../common/LocalizeInputNumber';
import styles from './style.css';
import {currency, saleOrderPriceTerms, paymentType, saleOrderTransportTypeForKd, proformaInvoiceSource, isYesNo} from '../Enum';
import DescriptionList from 'ant-design-pro/lib/DescriptionList';
import ImportPanel from './ImportPanel';
import ImportPartPanel from './ImportPartPanel';
import WrappedDatePicker from '../common/WrappedDatePicker';
const {Description} = DescriptionList;
let batchNumberSign = '';
export class NewPanel extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        validate: false,
        valiSaleOrder: false,
        carrierList: [],
        data: {
            countryOfOrigin: 'People\'s Republic of China',
            dataSource: 3,
            brandId: '',
            carrierCode: '',
            carrierName: '',
            isBatchNumber: false,
            ifUseBatchNumberToPrint: 0
        },
        details: [],
        saleProformaPartDetails: [],
        showBankSelectPanel: false,
        showSaleOrderPanel: false,
        showSaleOrderDetailPanel: false,
        showKdClaimPanel: false,
        isKDClaim: false,
        showImportPanel: false,
        showPartImportPanel: false
    };

    componentDidMount() {
        this.getDetailInfo();
        // const partSaleOrder = getUrl(this.props.history.location.search);
        // if(partSaleOrder && partSaleOrder.id)
        //     getKDClaimDetail(partSaleOrder.id)
        //         .then(res => {
        //             if(res.ok) {
        //                 const row = res.data;
        //                 const tmp = row.details.map(d => Object.assign({}, d, {
        //                     order: row.details.findIndex(x => x.id === d.id) + 1,
        //                     dataSource: proformaInvoiceSourceKd.KD索赔单,
        //                     sourceCode: row.code,
        //                     KDBomCode: d.kdBomCode,
        //                 }));
        //                 this.setState({
        //                     details: tmp,
        //                     data: Object.assign({}, this.state.data, {
        //                         dataSource: proformaInvoiceSourceKd.KD索赔单,
        //                         brandId: row.brandId,
        //                         brandCode: row.brandCode,
        //                         brandName: row.brandName,
        //                         dealerId: row.dealerId,
        //                         dealerCode: row.dealerCode,
        //                         dealerName: row.dealerName,
        //                     }),
        //                     hasOperat: true,
        //                     isKDClaim: true,
        //                 });
        //             }
        //         });
    }
    
    componentWillUnmount() {
        this.isunmount = true;
    }
    getDetailInfo = () => {
        if(this.props.id) {
            this.setState(({
                isFetching: true
            }));
            getDetail(this.props.id)
                .then(res => {
                    if(res.ok) {
                        if(this.state.data.brandId) {
                            const condition = {
                                brandId: this.state.data.brandId
                            };
                            this.getCarrier(condition);
                        }
                        if(!this.state.data.brandId && this.props.initEnum.brands.length !== 0) {
                            const condition = {
                                brandId: this.props.initEnum.brands[0].value
                            };
                            this.getCarrier(condition);
                        }
                        res.data.ifUseBatchNumberToPrint = res.data.ifUseBatchNumberToPrint ? 1 : 0;
                        this.setState({
                            isFetching: false,
                            data: res.data,
                            details: res.data.saleProformaInvoiceDetails,
                            saleProformaPartDetails: res.data.saleProformaPartDetails
                        });
                    } else
                        this.setState(({
                            isFetching: false
                        }));
                });
        }
    }
    handleFilterChange = (value, name) => {
        if(this.state.data.brandId && name === 'dealerId') {
            const condition = {
                brandId: this.state.data.brandId
            };
            this.getCarrier(condition);
        }
        if(!this.state.data.brandId && name === 'dealerId') {
            const condition = {
                brandId: this.props.initEnum.brands[0].value
            };
            this.getCarrier(condition);
        }
        if(name === 'batchNumber' && value !== batchNumberSign)
            this.state.data.isBatchNumber = true;
        if(name === 'batchNumber' && value === batchNumberSign)
            this.state.data.isBatchNumber = false;
        if(name === 'dataSource') {
            this.state.validate = false;
            this.state.valiSaleOrder = false;
            this.state.details = [];
            this.state.data = {
                countryOfOrigin: 'People\'s Republic of China',
                dataSource: 3
            };
        }
        const data = Object.assign({}, this.state.data, {
            [name]: value
        });
        this.setState({
            data,
            hasOperat: true
        });
    }
    
    // eslint-disable-next-line react/sort-comp
    onClickCurrency = (value, name) => {
        if(this.state.data.dataSource === proformaInvoiceSource.整车销售订单 && this.state.details.length > 0 && Boolean(this.state.data.currency) && this.state.data.currency !== value)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch2',
                    defaultMessage: '提示'
                }),
                content: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch.currency',
                    defaultMessage: '变更币种，将会清空清单数据，是否清空？'
                }),
                onOk: () => this.onChangeSwitchOther(value, name)
            });
        else {
            const data = Object.assign({}, this.state.data, {
                [name]: value,
            });
            this.setState({
                data,
                hasOperat: true
            });
        }
    }
    onClickTradeMethodId = (value, name) => {
        if(this.state.data.dataSource === proformaInvoiceSource.整车销售订单 && this.state.details.length > 0 && Boolean(this.state.data.tradeMethodId) && this.state.data.tradeMethodId !== value)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch2',
                    defaultMessage: '提示'
                }),
                content: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch.tradeMethodId',
                    defaultMessage: '变更贸易方式，将会清空清单数据，是否清空？'
                }),
                onOk: () => this.onChangeSwitchOther(value, name)
            });
        else {
            const data = Object.assign({}, this.state.data, {
                [name]: value,
            });
            this.setState({
                data,
                hasOperat: true
            });
        }
    }
    onClickPaymentType = (value, name) => {
        if(this.state.data.dataSource === proformaInvoiceSource.整车销售订单 && this.state.details.length > 0 && Boolean(this.state.data.paymentType) && this.state.data.paymentType !== value)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch2',
                    defaultMessage: '提示'
                }),
                content: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch.paymentType',
                    defaultMessage: '变更付款方式，将会清空清单数据，是否清空？'
                }),
                onOk: () => this.onChangeSwitchOther(value, name)
            });
        else {
            const data = Object.assign({}, this.state.data, {
                [name]: value
            });
            this.setState({
                data,
                hasOperat: true
            });
        }
    }
    
    onChangeSwitchOther = (value, name) => {
        const data = Object.assign({}, this.state.data, {
            [name]: value,
        });
        this.setState({
            data,
            details: [],
            hasOperat: true
        });
    }
    onClickReturnBtn = () => {
        this.props.onCancel();
    }
    
    onClickSaleOrderPriceTerms = (value, name) => {
        if(this.state.data.dataSource === proformaInvoiceSource.整车销售订单 && this.state.details.length > 0 && Boolean(this.state.data.saleOrderPriceTerms) && this.state.data.saleOrderPriceTerms !== value)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch2',
                    defaultMessage: '提示'
                }),
                content: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch.saleOrderPriceTerms',
                    defaultMessage: '变更价格条款，将会清空清单数据，是否清空？'
                }),
                onOk: () => this.onChangeSwitchOther(value, name)
            });
        else {
            const details = this.state.details;
            if(value === saleOrderPriceTerms.FOB ||
                value === saleOrderPriceTerms.FCA ||
                value === saleOrderPriceTerms.EXW)
                this.setState({
                    details
                });
            if(value === saleOrderPriceTerms.CPT ||
                value === saleOrderPriceTerms.CFR) {
                const data = this.state.data;
                if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                    data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                    data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) {
                    let totalShipmentAmount = 0;
                    if(details)
                        details.forEach(v => {
                            totalShipmentAmount += v.unitShipmentAmount * v.containerNumber;
                        });
                    this.setState({
                        data: Object.assign({}, data, {
                            shipmentAmount: totalShipmentAmount,
                            [name]: value
                        }),
                        hasOperat: true
                    });
                } else
                    this.setState({
                        data: Object.assign({}, this.state.data, {
                            [name]: value
                        }),
                        hasOperat: true
                    });
            } else if(value === saleOrderPriceTerms.CIF ||
                value === saleOrderPriceTerms.CIP) {
                const data = this.state.data;
                if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                    data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                    data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) {
                    let totalShipmentAmount = 0;
                    let totalInsuranceAmount = 0;
                    if(details)
                        details.forEach(v => {
                            totalShipmentAmount += v.unitShipmentAmount * v.containerNumber;
                            totalInsuranceAmount += (v.unitInsuranceAmount ? v.unitInsuranceAmount : 0) * v.quantity;
                        });
                    this.setState({
                        data: Object.assign({}, data, {
                            shipmentAmount: totalShipmentAmount,
                            insuranceAmount: totalInsuranceAmount,
                            [name]: value
                        }),
                        hasOperat: true
                    });
                } else
                    this.setState({
                        data: Object.assign({}, this.state.data, {
                            [name]: value
                        }),
                        hasOperat: true
                    });
            } else {
                const data = Object.assign({}, this.state.data, {
                    [name]: value,
                    payableAccount: value !== saleOrderPriceTerms.FCA ? '' : this.state.data.payableAccount,
                    carrierId: (value === saleOrderPriceTerms.FOB ||
                        value === saleOrderPriceTerms.FCA ||
                        value === saleOrderPriceTerms.EXW) ? this.state.data.carrierId : ''
                });
                this.setState({
                    data,
                    hasOperat: true
                });
            }
        }
    }
    onClickDeliveryTerms = (value, name) => {
        if(this.state.data.dataSource === proformaInvoiceSource.整车销售订单 && this.state.details.length > 0 && Boolean(this.state.data.deliveryTerms) && this.state.data.deliveryTerms !== value)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch2',
                    defaultMessage: '提示'
                }),
                content: this.props.intl.formatMessage({
                    id: 'newPanel.message.switch.deliveryTerms',
                    defaultMessage: '变更运输方式，将会清空清单数据，是否清空？'
                }),
                onOk: () => this.onChangeSwitchOther(value, name)
            });
        else {
            const details = this.state.details;
            if(value === saleOrderTransportTypeForKd.Others || value === saleOrderTransportTypeForKd['By Air']) {
                let totalShipmentAmount = 0;
                if(details) {
                    details.forEach(v => {
                        totalShipmentAmount += (v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber;
                    });
                    this.setState({
                        data: Object.assign({}, this.state.data, {
                            shipmentAmount: totalShipmentAmount,
                            [name]: value
                        }),
                        details: details.map(v => Object.assign({}, v, {
                            containerNumber: 0,
                            unitShipmentAmount: 0
                        }))
                    });
                } else {
                    const data = Object.assign({}, this.state.data, {
                        [name]: value
                    });
                    this.setState({
                        data,
                        hasOperat: true
                    });
                }
            }
            if(value === saleOrderTransportTypeForKd.Container ||
                value === saleOrderTransportTypeForKd.Railway ||
                value === saleOrderTransportTypeForKd['By Sea']) {
                let totalShipmentAmount = 0;
                if(details) {
                    details.forEach(v => {
                        totalShipmentAmount += (v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber;
                    });
                    this.setState({
                        data: Object.assign({}, this.state.data, {
                            shipmentAmount: totalShipmentAmount,
                            [name]: value
                        })
                    });
                } else {
                    const data = Object.assign({}, this.state.data, {
                        [name]: value
                    });
                    this.setState({
                        data,
                        hasOperat: true
                    });
                }
            }
        }
    }
    onSubmit = () => {
        const isValid = newOrUpdateOrderValidator(this.state.data, this.state.details, this.state.saleProformaPartDetails);
        if(!isValid) {
            this.setState({
                validate: true
            });
            return;
        }
        this.setState({
            loading: true,
        });
        this.props.onSubmit(this.state.data, this.state.details, this.state.saleProformaPartDetails).then(() => {
            if(this.success)
                this.props.successReturn();
            if(!this.isunmount)
                this.setState({loading: false});
        });
    }
    
    onSelectDealer = (condition = {}) => {
        if(this.props.initEnum.brands.length === 1)
            this.state.data.brandId = this.props.initEnum.brands[0].value;
        if(!this.state.data.brandId)
            msg.warn(this.props.intl.formatMessage({
                id: 'NewPanel.message.choseBrand',
                defaultMessage: '请先选择品牌'
            }));
        if(this.state.data.brandId)
            this.setState(state => {
                const newData = cloneDeep(state.data);
                return {
                    hasOperat: true,
                    data: {
                        ...newData,
                        dealerId: condition.id,
                        dealerCode: condition.code,
                        dealerName: condition.name,
                        address: condition.address,
                        zipCode: condition.zipCode,
                        contactNumber: condition.contactPhone,
                        country: condition.countryName,
                        marketDepartmentName: condition.marketDepartmentName
                    }
                };
            });
        if(condition.id && this.state.data.dataSource === proformaInvoiceSource.手工录入) {
            this.queryDealerSaleInformation(condition.id);
            this.setState({
                details: [],
            });
        }
        if(!condition.id) {
            const newData = cloneDeep(this.state.data);
            this.setState({
                data: {
                    ...newData,
                    currency: undefined,
                    tradeMethodId: '',
                    tradeMethodName: '',
                    salesOrderPriceTerms: undefined,
                    paymentType: undefined,
                    account: '',
                    carrierId: '',
                    carrierCode: '',
                    carrierName: '',
                    shippingPortId: '',
                    shippingPortCode: '',
                    shippingPortName: '',
                    destinationPort: '',
                    batchNumber: '',
                    CNPJ: '',
                    buyer: '',
                    contact: '',
                    TELEX: '',
                    deliveryTerms: undefined,
                    address: '',
                    zipCode: '',
                    contactNumber: '',
                    country: '',
                    marketDepartmentName: '',
                },
                details: [],
            });
        }
    };
    getCarrier = condition => {
        getCarriers(condition).then(res => {
            if(res.ok)
                this.setState({
                    carrierList: res.data.content.map(item => ({
                        text: `${'('}${item.code}${')'}${item.name}`,
                        value: item.id
                    }))
                });
        });
    }
    queryDealerSaleInformation = dealerId => {
        const id = dealerId;
        const queryCondition = {
            brandId: this.state.data.brandId,
            dealerId: id,
            isCBU: false
        };
        getDealerSaleInformations(queryCondition).then(res => {
            if(res.ok) {
                batchNumberSign = res.data.batchNumber;
                if(this.state.data.brandId) {
                    const condition = {
                        brandId: this.state.data.brandId
                    };
                    this.getCarrier(condition);
                }
                if(!this.state.data.brandId) {
                    const condition = {
                        brandId: this.props.initEnum.brands[0].value
                    };
                    this.getCarrier(condition);
                }
                this.setState(state => {
                    const newData = cloneDeep(state.data);
                    return {
                        hasOperat: true,
                        data: {
                            ...newData,
                            currency: res.data.currency,
                            tradeMethodId: res.data.tradeMethodId,
                            tradeMethodName: res.data.tradeMethodName,
                            salesOrderPriceTerms: res.data.priceClause,
                            paymentType: res.data.paymentType,
                            account: res.data.account,
                            carrierId: res.data.carrierId,
                            carrierCode: res.data.carrierCode,
                            carrierName: res.data.carrierName,
                            shippingPortId: res.data.shippingPortId,
                            shippingPortCode: res.data.shippingPortCode,
                            shippingPortName: res.data.shippingPortName,
                            destinationPort: res.data.destinationPort,
                            batchNumber: res.data.batchNumber,
                            CNPJ: res.data.CNPJ,
                            buyer: res.data.buyer,
                            contact: res.data.contact,
                            TELEX: res.data.TELEX,
                            deliveryTerms: res.data.deliveryTerms
                        }
                    };
                });
            }
        });
    }
    onClickBankSearchBtn = () => {
        if(!this.state.data.dealerId)
            return msg.warn(this.props.intl.formatMessage({
                id: 'NewPanel.message.choseDealer',
                defaultMessage: '请先选择总代'
            }));
        if(!this.state.data.tradeMethodId)
            return msg.warn(this.props.intl.formatMessage({
                id: 'NewPanel.message.tradeMethodId',
                defaultMessage: '请先选择贸易方式'
            }));
        if(!this.state.data.currency)
            return msg.warn(this.props.intl.formatMessage({
                id: 'NewPanel.message.currency',
                defaultMessage: '请先选择币种'
            }));
        this.setState({showBankSelectPanel: true});
    }
    onCloseBankSelectPanel = () => {
        this.setState({showBankSelectPanel: false});
    }
    onSelectAddedBank = records => {
        this.setState({
            data: Object.assign({}, this.state.data, {
                bankId: records.id,
                bankAccount: records.account,
                bankName: records.name
            }),
            hasOperat: true,
            showBankSelectPanel: false
        });
    }
    onClickAddSaleOrderBtn = () => {
        // const isValid = saleOrderValidator(this.state.data);
        // if(!isValid) {
        //     this.setState({
        //         valiSaleOrder: true,
        //     });
        //     return;
        // }
        this.setState({showSaleOrderPanel: true});
    }
    onClickAddKdClaimBtn = () => {
        if(!this.state.data.dealerId)
            return msg.warn(this.props.intl.formatMessage({
                id: 'NewPanel.message.choseDealer',
                defaultMessage: '请先选择总代'
            }));
        this.setState({showKdClaimPanel: true});
    }
    onCloseSaleOrderPanel = () => {
        this.setState({showSaleOrderPanel: false});
    }
    onSelectSaleOrder = records => {
        this.setState({
            data: Object.assign({}, this.state.data, {
                saleOrderId: records.id,
                saleOrderCode: records.code,
                // currency: records.currency,
                // tradeMethodId: records.tradeMethodId,
                // tradeMethodName: records.tradeMethodName,
                // paymentType: records.paymentType,
                // deliveryTerms: records.transportType,
                // salesOrderPriceTerms: records.salesOrderPriceTerms,
                // descriptionOfGoods: records.descriptionOfGoods
            }),
            hasOperat: true,
            showSaleOrderPanel: false,
            showSaleOrderDetailPanel: true
        });
    }
    onCloseKdClaimPanel = () => {
        this.setState({showKdClaimPanel: false});
    }
    onSelectKdClaim = records => {
        this.setState({
            data: Object.assign({}, this.state.data, {
                kdClaimId: records.id,
            }),
            hasOperat: true,
            showKdClaimPanel: false,
        });
        const condition = {
            id: records.id
        };
        this.onQuery(condition);
    }
    onClickImportBtn = () => {
        this.setState({showImportPanel: true});
    }
    onCloseImportPanel = () => {
        this.setState({showImportPanel: false});
    }
    onClickImportPartBtn = () => {
        this.setState({showPartImportPanel: true});
    }
    onClosePartImportPanel = () => {
        this.setState({showPartImportPanel: false});
    }
    onQuery = condition => {
        getKdClaimDetails(condition)
            .then(res => {
                if(res.ok) {
                    const retailDetails = this.state.details || [];
                    res.data.details.forEach(r => {
                        const index = retailDetails.findIndex(v => v.id === r.id);
                        if(index === -1)
                            retailDetails.push({
                                id: r.id,
                                dataSource: 2,
                                sourceCode: r.code,
                                kdBomCode: r.KDBomCode,
                            });
                    });
                    this.setState({
                        details: [...retailDetails],
                        hasOperat: true,
                    });
                } else
                    this.setState({
                        isFetching: false,
                    });
            });
    }
    onDeleteAll = () => {
        this.setState({
            details: [],
            hasOperat: true,
        });
    }
    onDeleteDetail = e => {
        const id = e.target.dataset.id;
        const tmp = this.state.details.filter(d => d.id !== id);
        if(this.state.details.length !== 0)
            this.setState({
                details: [...tmp],
                hasOperat: true,
            });
        if(this.state.details.length === 0)
            this.setState({
                data: {dataSource: undefined}
            });
    }
    onDeleteDetails = e => {
        const id = e.target.dataset.partCode;
        const tmp = this.state.saleProformaPartDetails.filter(d => d.partCode !== id);
        if(this.state.saleProformaPartDetails.length !== 0)
            this.setState({
                saleProformaPartDetails: [...tmp],
                hasOperat: true,
            });
    }
    onDeleteDetailAll = () => {
        this.setState({
            saleProformaPartDetails: [],
            hasOperat: true,
        });
    }
    onUpdateQuantity = (quantity, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    quantity,
                });
            return d;
        });
        const data = this.state.data;
        if((data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP) && (data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea'])) {
            let totalInsuranceAmount = 0;
            if(tmp)
                tmp.forEach(v => {
                    totalInsuranceAmount += ((((v.price ? v.price : 0) + ((v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber)) * 0.044)) * v.quantity;
                });
            this.setState({
                data: Object.assign({}, data, {
                    insuranceAmount: totalInsuranceAmount
                }),
                hasOperat: true
            });
        }
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    priceOnChange = (price, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    price,
                });
            return d;
        });
        const data = this.state.data;
        if((data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP) && (data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea'])) {
            let totalInsuranceAmount = 0;
            if(tmp)
                tmp.forEach(v => {
                    totalInsuranceAmount += ((((v.price ? v.price : 0) + ((v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber)) * 0.044)) * v.quantity;
                });
            this.setState({
                data: Object.assign({}, data, {
                    insuranceAmount: totalInsuranceAmount
                }),
                hasOperat: true
            });
        }
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onKDBomCodeChange = (kdBomCode, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    kdBomCode,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onDescriptionOfGoodsChange = (descriptionOfGoods, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    descriptionOfGoods,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onUpdateLaborHour = (laborHour, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    laborHour,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onUpdateLaborPrice = (laborPrice, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    laborPrice,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onRemarkChange = (remark, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    remark,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    unitShipmentAmountOnChange = (unitShipmentAmount, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    unitShipmentAmount,
                });
            return d;
        });
        const data = this.state.data;
        if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) {
            let totalShipmentAmount = 0;
            let totalInsuranceAmount = 0;
            if(tmp)
                tmp.forEach(v => {
                    totalShipmentAmount += v.unitShipmentAmount * v.containerNumber;
                    totalInsuranceAmount += ((((v.price ? v.price : 0) + ((v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber)) * 0.044)) * v.quantity;
                });
            if(data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP)
                this.setState({
                    data: Object.assign({}, data, {
                        shipmentAmount: totalShipmentAmount,
                        insuranceAmount: totalInsuranceAmount
                    })
                });
            else this.setState({
                data: Object.assign({}, data, {
                    shipmentAmount: totalShipmentAmount
                })
            });
        }
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    unitInsuranceAmountOnChange = (unitInsuranceAmount, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    unitInsuranceAmount,
                });
            return d;
        });
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onUpdateContainerNumber = (containerNumber, id) => {
        const details = this.state.details || [];
        const tmp = details.map(d => {
            if(d.id === id)
                return Object.assign({}, d, {
                    containerNumber,
                });
            return d;
        });
        const data = this.state.data;
        if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) {
            let totalShipmentAmount = 0;
            let totalInsuranceAmount = 0;
            if(tmp)
                tmp.forEach(v => {
                    totalShipmentAmount += (v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber;
                    totalInsuranceAmount += ((((v.price ? v.price : 0) + ((v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber)) * 0.044)) * v.quantity;
                });
            
            if(data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP)
                this.setState({
                    data: Object.assign({}, data, {
                        shipmentAmount: totalShipmentAmount,
                        insuranceAmount: totalInsuranceAmount
                    })
                });
            else this.setState({
                data: Object.assign({}, data, {
                    shipmentAmount: totalShipmentAmount
                })
            });
        }
        this.setState({
            details: tmp,
            hasOperat: true
        });
    }
    onSelectAddedSaleOrderDetail = records => {
        const retailDetails = this.state.details || [];
        records.forEach(r => {
            const index = retailDetails.findIndex(v => v.saleOrderDetailId === r.id);
            if(index === -1)
                retailDetails.push({
                    id: r.id,
                    saleOrderId: r.saleOrderId,
                    saleOrderDetailId: r.id,
                    // dataSource: 1,
                    sourceCode: r.sourceCode,
                    kdBomCode: r.kdBomCode,
                    descriptionOfGoods: r.descriptionOfGoods,
                    quantity: r.quantity,
                    containerNumber: r.containerNumber ? r.containerNumber : 1,
                    price: r.price ? r.price : 0,
                    totalPrice: r.totalPrice,
                    unitShipmentAmount: 0,
                    unitInsuranceAmount: 0,
                    oldQuantity: r.quantity,
                    currency: r.currency,
                    paymentType: r.paymentType,
                    salesOrderPriceTerms: r.salesOrderPriceTerms,
                    transportType: r.transportType,
                    tradeMethodId: r.tradeMethodId,
                    tradeMethodName: r.tradeMethodName,
                });
        });
        this.setState({
            details: [...retailDetails],
            data: Object.assign({}, this.state.data, {
                currency: records[0].currency,
                paymentType: records[0].paymentType,
                salesOrderPriceTerms: records[0].salesOrderPriceTerms,
                deliveryTerms: records[0].transportType,
                tradeMethodId: records[0].tradeMethodId,
                tradeMethodName: records[0].tradeMethodName,
            }),
            hasOperat: true,
            showSaleOrderDetailPanel: false
        });
    }
    onCloseSaleOrderDetailPanel = () => {
        this.setState({showSaleOrderDetailPanel: false});
    }
    onClickAddDetailBtn = () => {
        const details = this.state.details;
        this.setState({
            details: [
                ...details,
                {
                    id: uuid(),
                    dataSource: 3,
                    quantity: 1,
                    price: 0,
                    containerNumber: 1,
                    unitShipmentAmount: 0,
                }
            ]
        });
    };
    onImportChange = records => {
        if(records.payload) {
            const retailDetails = this.state.details || [];
            records.payload.content.forEach(r => {
                const index = retailDetails.findIndex(v => v.kdBomCode === r.kdBomCode);
                const detail = retailDetails.find(v => v.kdBomCode === r.kdBomCode);
                if(index === -1)
                    retailDetails.push({
                        id: r.id,
                        kdBomCode: r.kdBomCode,
                        descriptionOfGoods: r.descriptionOfGoods,
                        quantity: r.quantity || 0,
                        price: r.price || 0,
                        totalPrice: r.totalPrice,
                        remark: r.remark,
                        dataSource: 3,
                        containerNumber: 1,
                        unitShipmentAmount: 0,
                    });
                else
                    retailDetails.splice(index, 1, Object.assign({}, detail, {
                        descriptionOfGoods: r.descriptionOfGoods,
                        quantity: r.quantity || 0,
                        price: r.price || 0,
                        remark: r.remark,
                    }));
            });
            this.setState({
                details: [...retailDetails],
                hasOperat: true,
                showImportPanel: false,
                isAlert: true
            });
        }
    }
    onPartImportChange = records => {
        if(records.payload) {
            const retailDetails = this.state.saleProformaPartDetails || [];
            records.payload.content.forEach(r => {
                const index = retailDetails.findIndex(v => v.partCode === r.partCode);
                const detail = retailDetails.find(v => v.partCode === r.partCode);
                if(index === -1)
                    retailDetails.push({
                        id: r.id,
                        partCode: r.partCode,
                        partName: r.partName,
                        quantity: r.quantity,
                        price: r.price,
                    });
                else
                    retailDetails.splice(index, 1, Object.assign({}, detail, {
                        partName: r.partName,
                        quantity: r.quantity,
                        price: r.price,
                    }));
            });
            this.setState({
                saleProformaPartDetails: [...retailDetails],
                hasOperat: true,
                showPartImportPanel: false,
            });
        }
    }
    render() {
        const {data, details, saleProformaPartDetails, isKDClaim} = this.state;
        const dealerInfo = data.dealerId ? {
            id: data.dealerId,
            code: data.dealerCode,
            name: data.dealerName,
        } : null;
        const validateBrand = !data.brandId && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validateDealer = !data.dealerId && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validateCurrency = !data.currency && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validateTradeMethod = !data.tradeMethodId && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validateSalesOrderPriceTerms = //data.dataSource !== 2 &&
            !data.salesOrderPriceTerms && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validatePaymentType = //data.dataSource !== 2 &&
            !data.paymentType && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validateDeliveryTerms = !data.deliveryTerms && (data.dataSource === proformaInvoiceSource.整车销售订单 ? this.state.valiSaleOrder : this.state.validate) ? 'error' : null;
        const validateShippingPort = !data.shippingPortId && this.state.validate ? 'error' : null;
        const validateDestinationPort = !data.destinationPort && this.state.validate ? 'error' : null;
        const validateCarrierId = !data.carrierId && this.state.validate ? 'error' : null;
        const validatePayableAccount = !data.payableAccount && this.state.validate ? 'error' : null;
        const validateCommodity = //data.dataSource !== 2 &&
            !data.commodity && this.state.validate ? 'error' : null;
        const validateBank = !data.bankId && this.state.validate ? 'error' : null;
        const validateBatchNumber = !data.batchNumber && this.state.validate ? 'error' : null;
        const {formatMessage} = this.props.intl;
        const {pagePermission} = this.props;
        const submitable = hasPermissions(PERMISSION.add, pagePermission);
        let totalAmount = 0;
        let totalQuantity = 0;
        let totalShipmentAmount = 0;
        let totalInsuranceAmount = 0;
        let totalAmountSum = 0;
        if(details)
            details.forEach(v => {
                // if(data.dataSource === 2)
                //     totalAmount += ((v.laborHour ? v.laborHour : 0) * (v.laborPrice ? v.laborPrice : 0));
                if(data.dataSource === proformaInvoiceSource.整车销售订单 || data.dataSource === proformaInvoiceSource.手工录入) {
                    totalAmount += ((v.quantity ? v.quantity : 0) * (v.price ? v.price : 0));
                    totalAmountSum += ((v.price ? v.price : 0) * (v.quantity ? v.quantity : 0)) + ((v.unitShipmentAmount ? v.unitShipmentAmount : 0) * (v.containerNumber ? v.containerNumber : 0)) +
                    ((v.unitInsuranceAmount ? v.unitInsuranceAmount : 0) * (v.quantity ? v.quantity : 0));
                }
                totalQuantity += v.quantity;
                totalShipmentAmount += (v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber;
                totalInsuranceAmount += ((((v.price ? v.price : 0) + ((v.unitShipmentAmount ? v.unitShipmentAmount : 0) * v.containerNumber)) * 0.044)) * v.quantity;
            });
        const columns = [{
            title: formatMessage({
                id: 'newPanel.column.kdBomCode',
                defaultMessage: 'KDBOM号'
            }),
            dataIndex: 'kdBomCode',
            render: (text, record) => {
                const validate = (!text || text === undefined) ? {validateStatus: 'error'} : null;
                if(data.dataSource === proformaInvoiceSource.整车销售订单)// || data.dataSource === 2)
                    return text;
                if(data.dataSource === proformaInvoiceSource.手工录入)
                    return (<FormItem {...validate}>
                        <TextInput
                            id={record.id}
                            name="kdBomCode"
                            value={text}
                            onBlur={this.onKDBomCodeChange}/>
                    </FormItem>);
            }
        }, {
            title: formatMessage({
                id: 'newPanel.column.descriptionOfGoods',
                defaultMessage: '产品描述'
            }),
            dataIndex: 'descriptionOfGoods',
            render: (text, record) => {
                if(data.dataSource === proformaInvoiceSource.整车销售订单)
                    return text;
                if(data.dataSource === proformaInvoiceSource.手工录入)//data.dataSource === 2 || 
                    return (<FormItem>
                        <TextInput
                            id={record.id}
                            name="descriptionOfGoods"
                            value={text}
                            onBlur={this.onDescriptionOfGoodsChange}/>
                    </FormItem>);
            }
        }, {
            title: formatMessage({
                id: 'newPanel.column.totalPrice',
                defaultMessage: '总价'
            }),
            dataIndex: 'totalPrice',
            render: (text, record) => {
                // if(data.dataSource === 2)
                //     return ((record.laborHour ? record.laborHour : 0) * (record.laborPrice ? record.laborPrice : 0));
                if(data.dataSource === proformaInvoiceSource.整车销售订单 || data.dataSource === proformaInvoiceSource.手工录入)
                    return ((record.quantity ? record.quantity : 0) * (record.price ? record.price : 0));
            }
        }, {
            title: formatMessage({
                id: 'newPanel.column.amountSum',
                defaultMessage: '总金额'
            }),
            dataIndex: 'amountSum',
            // eslint-disable-next-line arrow-body-style
            render: (text, record) => {
                // if(data.deliveryTerms === 1 || data.deliveryTerms === 3 || data.deliveryTerms === 6)
                // eslint-disable-next-line no-return-assign
                return record.amountSum = formatAmount((((record.price ? record.price : 0) * record.quantity) + ((record.unitShipmentAmount ? record.unitShipmentAmount : 0) * record.containerNumber) +
                    ((record.unitInsuranceAmount ? record.unitInsuranceAmount : 0) * record.quantity)));
            }
        }, {
            title: formatMessage({
                id: 'newPanel.column.remark',
                defaultMessage: '备注'
            }),
            dataIndex: 'remark',
            render: (text, record) => (<FormItem>
                <TextInput
                    id={record.id}
                    name="remark"
                    value={text}
                    onBlur={this.onRemarkChange}/>
            </FormItem>)
        }, {
            title: details.length > 0
                ? (
                    <Popconfirm placement="topRight" title={formatMessage({
                        id: 'newPanel.validation.isDelete',
                        defaultMessage: '是否确认全部删除？'
                    })} onConfirm={this.onDeleteAll} >
                        <a>{formatMessage({
                            id: 'newPanel.validation.clear',
                            defaultMessage: '清空'
                        })}</a>
                    </Popconfirm>
                )
                : null,
            dataIndex: 'id',
            fixed: 'right',
            width: FIXED_COLUMN_WIDTH,
            render: text => <a data-id={text} onClick={this.onDeleteDetail}>{formatMessage({
                id: 'newPanel.validation.delete',
                defaultMessage: '删除'
            })}</a>
        }];
        if(data.dataSource !== proformaInvoiceSource.手工录入)
            columns.splice(0, 0,
                {
                    title: this.props.intl.formatMessage({
                        id: 'newPanel.column.sourceCode',
                        defaultMessage: '源单据编号'
                    }),
                    dataIndex: 'sourceCode',
                });
        // if(data.dataSource !== proformaInvoiceSourceKd.KD索赔单)
        columns.splice((data.dataSource === proformaInvoiceSource.整车销售订单 ? 3 : 2), 0,
            {
                title: formatMessage({
                    id: 'newPanel.column.quantity',
                    defaultMessage: '数量'
                }),
                dataIndex: 'quantity',
                width: 120,
                render: (text, record) => {
                    const validate = (!text || text === undefined) || text === 0 ? {validateStatus: 'error'} : null;
                    return (<FormItem {...validate}>
                        <LocalizeInputNumber
                            min={0}
                            max={data.dataSource === proformaInvoiceSource.整车销售订单 ? (record.oldQuantity || 0) : 99999999}
                            id={record.id}
                            precision={0}
                            value={text} onChange={this.onUpdateQuantity}/>
                    </FormItem>);
                }
            }, {
                title: formatMessage({
                    id: 'newPanel.column.price',
                    defaultMessage: '单价'
                }),
                dataIndex: 'price',
                width: 120,
                render: (text, record) => {
                    const validate = (!text || text === undefined) ? {validateStatus: 'error'} : null;
                    return (<FormItem {...validate}>
                        <InputAmount
                            precision={2}
                            id={record.id}
                            value={record.price}
                            onChange={this.priceOnChange}/>
                    </FormItem>);
                }
            });
        
        if(data.dataSource === proformaInvoiceSource.整车销售订单)
            columns.splice(4, 0,
                {
                    title: formatMessage({
                        id: 'newPanel.column.oldQuantity',
                        defaultMessage: '可用数量'
                    }),
                    dataIndex: 'oldQuantity',
                    render: text => text
                });
        //saleOrderTransportTypeForKd
        //当主单价格条款=CIF，CPT，CIP，CFR 时集装箱数、单位运费显示
        if(//data.dataSource !== proformaInvoiceSourceKd.KD索赔单 &&
            (data.salesOrderPriceTerms === saleOrderPriceTerms.CIF ||
                data.salesOrderPriceTerms === saleOrderPriceTerms.CPT ||
                data.salesOrderPriceTerms === saleOrderPriceTerms.CIP ||
                data.salesOrderPriceTerms === saleOrderPriceTerms.CFR))
            columns.splice((data.dataSource === proformaInvoiceSource.整车销售订单 ? 7 : 5), 0,
                {
                    title: formatMessage({
                        id: 'newPanel.column.containerNumber',
                        defaultMessage: '集装箱数'
                    }),
                    dataIndex: 'containerNumber',
                    width: 120,
                    render: (text, record) => {
                        const validate = ((!text || text === undefined) || text === 0) &&
                            (data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                                data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                                data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) ? {validateStatus: 'error'} : null;
                        return (data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) ? <FormItem {...validate}>
                                <LocalizeInputNumber
                                    min={0}
                                    id={record.id}
                                    value={text}
                                    onChange={this.onUpdateContainerNumber}/>
                            </FormItem>
                            : text;
                    }
                });
        if(//data.dataSource !== proformaInvoiceSourceKd.KD索赔 &&
            (data.salesOrderPriceTerms === saleOrderPriceTerms.CIF ||
                data.salesOrderPriceTerms === saleOrderPriceTerms.CPT ||
                data.salesOrderPriceTerms === saleOrderPriceTerms.CIP ||
                data.salesOrderPriceTerms === saleOrderPriceTerms.CFR))
            columns.splice((data.dataSource === proformaInvoiceSource.整车销售订单 ? 8 : 6), 0,
                {
                    title: formatMessage({
                        id: 'newPanel.column.unitShipmentAmount',
                        defaultMessage: '单位运费'
                    }),
                    dataIndex: 'unitShipmentAmount',
                    width: 120,
                    render: (text, record) => {
                        const validate = ((!text || text === undefined) || text === 0) &&
                            (data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                                data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                                data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) ? {validateStatus: 'error'} : null;
                        return ((data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) ? <FormItem {...validate}>
                                <InputAmount
                                    precision={2}
                                    id={record.id}
                                    value={record.unitShipmentAmount}
                                    onChange={this.unitShipmentAmountOnChange}/>
                            </FormItem> : text);
                    }
                });
        if(//data.dataSource !== proformaInvoiceSourceKd.KD索赔 &&
            (data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP))
            columns.splice((data.dataSource === proformaInvoiceSource.整车销售订单 ? 9 : 7), 0,
                {
                    title: formatMessage({
                        id: 'newPanel.column.unitInsuranceAmount',
                        defaultMessage: '单位保费'
                    }),
                    dataIndex: 'unitInsuranceAmount',
                    render: (text, record) => {
                        if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) {
                            record.unitInsuranceAmount = (((record.price ? record.price : 0) + ((record.unitShipmentAmount ? record.unitShipmentAmount : 0) * record.containerNumber)) * 0.044);
                            return formatAmount(record.unitInsuranceAmount);
                        }
                        return text;
                    }
                });
        if(//(data.dataSource !== proformaInvoiceSourceKd.KD索赔) &&
            data.salesOrderPriceTerms === saleOrderPriceTerms.CIF ||
            data.salesOrderPriceTerms === saleOrderPriceTerms.CPT ||
            data.salesOrderPriceTerms === saleOrderPriceTerms.CIP ||
            data.salesOrderPriceTerms === saleOrderPriceTerms.CFR)
            columns.splice((data.dataSource === proformaInvoiceSource.整车销售订单 ? 10 : 8), 0,
                {
                    title: formatMessage({
                        id: 'newPanel.column.shipmentAmountSum',
                        defaultMessage: '总运费'
                    }),
                    dataIndex: 'shipmentAmountSum',
                    render: (text, record) => {
                        if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea']) {
                            record.shipmentAmountSum = record.unitShipmentAmount * record.containerNumber;
                            return formatAmount(record.shipmentAmountSum);
                        }
                        return text;
                    }
                });
        if(//(data.dataSource !== proformaInvoiceSourceKd.KD索赔) &&
            data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP)
            columns.splice((data.dataSource === proformaInvoiceSource.整车销售订单 ? 11 : 9), 0,
                {
                    title: formatMessage({
                        id: 'newPanel.column.insuranceAmountSum',
                        defaultMessage: '总保费'
                    }),
                    dataIndex: 'insuranceAmountSum',
                    render: (text, record) => {
                        if(data.deliveryTerms === saleOrderTransportTypeForKd.Container ||
                            data.deliveryTerms === saleOrderTransportTypeForKd.Railway ||
                            data.deliveryTerms === saleOrderTransportTypeForKd['By Sea'])
                            return formatAmount((record.unitInsuranceAmount) * record.quantity);
                        return text;
                    }
                });
        const partColumns = [{
            title: formatMessage({
                id: 'newPanel.column.partCode',
                defaultMessage: '备件编号'
            }),
            dataIndex: 'partCode',
        }, {
            title: formatMessage({
                id: 'newPanel.column.partName',
                defaultMessage: '备件名称'
            }),
            dataIndex: 'partName',
        }, {
            title: formatMessage({
                id: 'newPanel.column.quantity',
                defaultMessage: '数量'
            }),
            dataIndex: 'quantity',
            width: 120,
            render: (text, record) => {
                const validate = (!text || text === undefined) || text === 0 ? {validateStatus: 'error'} : null;
                return (<FormItem {...validate}>
                    <LocalizeInputNumber
                        min={0}
                        max={data.dataSource === proformaInvoiceSource.整车销售订单 ? (record.oldQuantity || 0) : 99999999}
                        id={record.id}
                        precision={0}
                        value={text} onChange={this.onUpdateQuantity}/>
                </FormItem>);
            }
        }, {
            title: formatMessage({
                id: 'newPanel.column.price',
                defaultMessage: '单价'
            }),
            dataIndex: 'price',
            render: text => formatAmount(text)
        }, {
            title: details.length > 0
                ? (
                    <Popconfirm placement="topRight" title={formatMessage({
                        id: 'newPanel.validation.isDeleteAll',
                        defaultMessage: '是否确认全部删除？'
                    })} onConfirm={this.onDeleteDetailAll} >
                        <a>{formatMessage({
                            id: 'newPanel.validation.clear',
                            defaultMessage: '清空'
                        })}</a>
                    </Popconfirm>
                )
                : null,
            dataIndex: 'id',
            fixed: 'right',
            width: FIXED_COLUMN_WIDTH,
            render: text => <a data-id={text} onClick={this.onDeleteDetails}>{formatMessage({
                id: 'newPanel.validation.deleteDetail',
                defaultMessage: '删除'
            })}</a>
        }];
        return (
            <div className="form-standard">
                <Spin spinning={this.state.loading}>
                    <Form>
                        <Card {...FORM_OPTIONS.col} title={formatMessage({
                            id: 'newPanel.card.title',
                            defaultMessage: '基本信息'
                        })}>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={this.props.intl.formatMessage({
                                        id: 'newPanel.form.dataSource',
                                        defaultMessage: '数据来源'
                                    })}
                                    {...FORM_OPTIONS.item}>
                                        <WrappedSelect
                                            disabled={Boolean(this.props.id)}
                                            allowClear
                                            name="dataSource"
                                            value={data.dataSource}
                                            options={proformaInvoiceSource.toList(language)}
                                            onChange={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                {isKDClaim === true ? <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.brand',
                                            defaultMessage: '品牌'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateBrand} required>
                                        {data.brandCode === undefined ? '' : `(${data.brandCode})${data.brandCode}`}
                                    </FormItem>
                                </Col> : this.props.initEnum.brands.length !== 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.brand',
                                            defaultMessage: '品牌'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateBrand} required>
                                        <WrappedSelect
                                            allowClear
                                            name="brandId"
                                            value={data.brandId}
                                            options={this.props.initEnum.brands}
                                            onChange={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>}
                                {isKDClaim === true || this.props.id ? <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.dealerId',
                                            defaultMessage: '总代'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateDealer} required>
                                        {data.dealerCode === undefined ? '' : `(${data.dealerCode})${data.dealerName}`}
                                    </FormItem>
                                </Col> : <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.dealerId',
                                            defaultMessage: '总代'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateDealer} required>
                                        <DealerSelectPanel
                                            value={dealerInfo}
                                            name="dealerId"
                                            onChange={this.handleFilterChange}
                                            onSelect={this.onSelectDealer} />
                                    </FormItem>
                                </Col>}
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.batchNumber',
                                            defaultMessage: '批次号'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateBatchNumber} required>
                                        <TextInput
                                            name="batchNumber"
                                            value={data.batchNumber}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.ifUseBatchNumberToPrint',
                                            defaultMessage: '使用批次号打印'
                                        })} {...FORM_OPTIONS.item}>
                                        <WrappedSelect
                                            allowClear
                                            name="ifUseBatchNumberToPrint"
                                            value={data.ifUseBatchNumberToPrint}
                                            options={isYesNo.toList(language)}
                                            onChange={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.country',
                                            defaultMessage: '国家'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {data.country}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.countryOfOrigin',
                                            defaultMessage: '原产国'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="countryOfOrigin"
                                            value={data.countryOfOrigin}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.countryOfDestination',
                                            defaultMessage: '目的国'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="countryOfDestination"
                                            value={data.countryOfDestination}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.address',
                                            defaultMessage: '地址'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {data.address}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.contactNumber',
                                            defaultMessage: '电话'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="contactNumber"
                                            value={data.contactNumber}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.zipCode',
                                            defaultMessage: '邮政编码'
                                        })} {...FORM_OPTIONS.item}>
                                        {data.zipCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.formC.marketDepartmentName',
                                            defaultMessage: '大区'
                                        })} {...FORM_OPTIONS.item}>
                                        {data.marketDepartmentName}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.currency',
                                            defaultMessage: '币种'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateCurrency} required>
                                        <WrappedSelect
                                            allowClear
                                            name="currency"
                                            value={data.currency}
                                            options={currency.toList(language)}
                                            onChange={this.onClickCurrency}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.tradeMethod',
                                            defaultMessage: '贸易方式'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateTradeMethod} required>
                                        <WrappedSelect
                                            allowClear
                                            name="tradeMethodId"
                                            value={data.tradeMethodId}
                                            options={this.props.initEnum.tradeMethods}
                                            onChange={this.onClickTradeMethodId}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.form.salesOrderPriceTerms',
                                        defaultMessage: '价格条款'
                                    })} {...FORM_OPTIONS.item} validateStatus={validateSalesOrderPriceTerms} required>
                                        <WrappedSelect
                                            allowClear
                                            name="salesOrderPriceTerms"
                                            value={data.salesOrderPriceTerms}
                                            options={saleOrderPriceTerms.toList(language)}
                                            onChange={this.onClickSaleOrderPriceTerms}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.form.paymentType',
                                        defaultMessage: '付款方式'
                                    })} {...FORM_OPTIONS.item} validateStatus={validatePaymentType} required>
                                        <WrappedSelect
                                            allowClear
                                            name="paymentType"
                                            value={data.paymentType}
                                            options={paymentType.toList(language)}
                                            onChange={this.onClickPaymentType}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.form.deliveryTerms',
                                        defaultMessage: '运输方式'
                                    })} {...FORM_OPTIONS.item} validateStatus={validateDeliveryTerms} required>
                                        <WrappedSelect
                                            allowClear
                                            name="deliveryTerms"
                                            value={data.deliveryTerms}
                                            options={saleOrderTransportTypeForKd.toList(language)}
                                            onChange={this.onClickDeliveryTerms}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.cnpj',
                                            defaultMessage: '法人国家登记号'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="cnpj"
                                            value={data.cnpj}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.buyer',
                                            defaultMessage: '购买人'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="buyer"
                                            value={data.buyer}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.contact',
                                            defaultMessage: '联系人'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="contact"
                                            value={data.contact}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.telex',
                                            defaultMessage: '电传'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="telex"
                                            value={data.telex}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                {//data.dataSource !== proformaInvoiceSourceKd.KD索赔 &&
                                    (data.salesOrderPriceTerms === saleOrderPriceTerms.CIF ||
                                    data.salesOrderPriceTerms === saleOrderPriceTerms.CPT ||
                                    data.salesOrderPriceTerms === saleOrderPriceTerms.CIP ||
                                    data.salesOrderPriceTerms === saleOrderPriceTerms.CFR) && <Col {...FORM_OPTIONS.col}>
                                        <FormItem label={formatMessage({
                                            id: 'newPanel.form.shipmentAmount',
                                            defaultMessage: '运费汇总'
                                        })} {...FORM_OPTIONS.item}>
                                            <InputAmount
                                                name="shipmentAmount"
                                                precision={2}
                                                value={data.shipmentAmount}
                                                onChange={this.handleFilterChange}/>
                                        </FormItem>
                                    </Col>
                                }
                                {//data.dataSource !== proformaInvoiceSourceKd.KD索赔 &&
                                    (data.salesOrderPriceTerms === saleOrderPriceTerms.CIF || data.salesOrderPriceTerms === saleOrderPriceTerms.CIP) &&
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.form.insuranceAmount',
                                        defaultMessage: '保费汇总'
                                    })} {...FORM_OPTIONS.item}>
                                        <InputAmount
                                            name="insuranceAmount"
                                            precision={2}
                                            value={data.insuranceAmount}
                                            onChange={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                                }
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.operation.certificationAmount',
                                        defaultMessage: '认证费用'
                                    })} {...FORM_OPTIONS.item}>
                                        <InputAmount
                                            name="certificationAmount"
                                            precision={2}
                                            value={data.certificationAmount}
                                            onChange={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                {data.salesOrderPriceTerms === saleOrderPriceTerms.FCA && <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.payableAccount',
                                            defaultMessage: '到付账号'
                                        })} {...FORM_OPTIONS.item} validateStatus={validatePayableAccount} required>
                                        <TextInput
                                            name="payableAccount"
                                            value={data.payableAccount}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>}
                                {(data.salesOrderPriceTerms === saleOrderPriceTerms.FOB ||
                                data.salesOrderPriceTerms === saleOrderPriceTerms.FCA ||
                                data.salesOrderPriceTerms === saleOrderPriceTerms.EXW) &&
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.carrier',
                                            defaultMessage: '指定货代'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateCarrierId} required>
                                        <WrappedSelect
                                            name="carrierId"
                                            options={this.state.carrierList}
                                            value={data.carrierId}
                                            onChange={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                }
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.shippingPort',
                                            defaultMessage: '发运港口'
                                        })}
                                        {...FORM_OPTIONS.item} validateStatus={validateShippingPort} required>
                                        <WrappedSelect
                                            allowClear
                                            name="shippingPortId"
                                            value={data.shippingPortId}
                                            options={this.props.initEnum.shippingPorts}
                                            onChange={this.handleFilterChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.destinationPort',
                                            defaultMessage: '目的港口'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateDestinationPort} required>
                                        <TextInput
                                            name="destinationPort"
                                            value={data.destinationPort}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.estimatedDeliveryDate',
                                            defaultMessage: '预计交货日期'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <WrappedDatePicker
                                            name="estimatedDeliveryDate"
                                            value={data.estimatedDeliveryDate}
                                            onChange={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'queryPanel.form.validity',
                                            defaultMessage: '报价有效期'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <WrappedDatePicker
                                            name="validity"
                                            value={data.validity}
                                            onChange={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.commodity',
                                            defaultMessage: 'PI描述'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateCommodity} required>
                                        <TextInput
                                            name="commodity"
                                            value={data.commodity}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.packing',
                                            defaultMessage: '包装描述'
                                        })} {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="packing"
                                            value={data.packing}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'newPanel.form.remark',
                                            defaultMessage: '备注'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <TextInput
                                            name="remark"
                                            value={data.remark}
                                            onBlur={this.handleFilterChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                        </Card>
                        <Card title={formatMessage({
                            id: 'newPanel.column.other',
                            defaultMessage: '银行信息'
                        })}>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.column.bankAccount',
                                        defaultMessage: '银行账号'
                                    })} {...FORM_OPTIONS.item} validateStatus={validateBank} required>
                                        <SearchInput
                                            disabled={true}
                                            value={data.bankAccount}
                                            onClickSearchBtn={this.onClickBankSearchBtn}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'newPanel.column.bankName',
                                        defaultMessage: '银行名称'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.bankName}
                                    </FormItem>
                                </Col>
                            </Row>
                        </Card>
                        <Card
                            title={<Row>
                                <Col {...FORM_OPTIONS.col}>
                                    {this.props.intl.formatMessage({
                                        id: 'newPanel.details',
                                        defaultMessage: 'PI形式发票清单'
                                    })}
                                </Col>
                            </Row>}
                            extra={<div>
                                <Button
                                    size="small"
                                    disabled={data.dataSource !== proformaInvoiceSource.手工录入 || !data.dealerId}
                                    onClick={this.onClickImportBtn}>
                                    {formatMessage({
                                        id: 'newPanel.operation.import',
                                        defaultMessage: '导入清单'
                                    })}
                                </Button>
                                <Button
                                    disabled={data.dataSource !== proformaInvoiceSource.整车销售订单 || !data.dealerId}
                                    size="small"
                                    onClick={this.onClickAddSaleOrderBtn}>
                                    {formatMessage({
                                        id: 'newPanel.operation.newSaleOrderDetail',
                                        defaultMessage: '根据订单新增清单'
                                    })}
                                </Button>
                                {/* <Button
                                    disabled={!data.dealerId}
                                    size="small"
                                    onClick={this.onClickAddKdClaimBtn}>
                                    {formatMessage({
                                        id: 'newPanel.operation.newKdClaimDetail',
                                        defaultMessage: '根据KD索赔单新增清单'
                                    })}
                                </Button> */}
                            </div>}>
                            <Button
                                type="dashed"
                                icon="plus"
                                block
                                disabled={data.dataSource !== proformaInvoiceSource.手工录入 || !data.dealerId}
                                className={styles.plusBtn}
                                onClick={this.onClickAddDetailBtn}>
                                {formatMessage({
                                    id: 'newPanel.operation.newDetail',
                                    defaultMessage: '新增'
                                })}
                            </Button>
                            <Table
                                className="white-space-nowrap"
                                columns={columns}
                                rowKey="id"
                                pagination={false}
                                dataSource={details}
                                footer={() => <DescriptionList>
                                    <Description term={formatMessage({
                                        id: 'newPanel.operation.totalQuantity',
                                        defaultMessage: '数量汇总'
                                    })}>{totalQuantity}
                                    </Description>
                                    <Description term={formatMessage({
                                        id: 'newPanel.operation.totalAmount',
                                        defaultMessage: '总价汇总'
                                    })}><strong>{formatAmount(totalAmount)}</strong>
                                    </Description>
                                    {(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 5 ||
                                        data.salesOrderPriceTerms === 6 || data.salesOrderPriceTerms === 2) && <Description term={formatMessage({
                                        id: 'newPanel.operation.totalShipmentAmount',
                                        defaultMessage: '运费汇总'
                                    })}>{formatAmount(totalShipmentAmount)}
                                    </Description>}
                                    {(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 6) && <Description term={formatMessage({
                                        id: 'newPanel.operation.totalInsuranceAmount',
                                        defaultMessage: '保费汇总'
                                    })}>{formatAmount(totalInsuranceAmount)}
                                    </Description>}
                                    <Description term={formatMessage({
                                        id: 'newPanel.operation.totalAmountSum',
                                        defaultMessage: '金额汇总'
                                    })}><strong>{formatAmount(totalAmountSum)}</strong>
                                    </Description>
                                </DescriptionList>}
                                {...TABLE} />
                        </Card>
                        <Card
                            title={this.props.intl.formatMessage({
                                id: 'newPanel.partDetails',
                                defaultMessage: 'PI备件清单'
                            })}
                            extra={<Button
                                size="small"
                                onClick={this.onClickImportPartBtn}>
                                {formatMessage({
                                    id: 'newPanel.operation.import',
                                    defaultMessage: '导入清单'
                                })}
                            </Button>}>
                            <Table
                                className="white-space-nowrap"
                                columns={partColumns}
                                rowKey="id"
                                pagination={false}
                                dataSource={saleProformaPartDetails}
                                {...TABLE} />
                        </Card>
                        <Card type="inner">
                            <Row>
                                <Col disabled={!submitable} className="col-align-right">
                                    <Button key="submit" loading={this.state.loading}
                                        onClick={this.onSubmit} type="primary">{formatMessage({
                                            id: 'newPanel.btn.submit',
                                            defaultMessage: '保存'
                                        })}</Button>
                                </Col>
                            </Row>
                        </Card>
                    </Form>
                </Spin>
                <div className="page-toolbar">
                    <Return
                        onConfirm={this.onClickReturnBtn}
                        disabled={this.state.loading}
                        showWarning={this.state.hasOperat} />
                </div>
                {
                    this.state.showBankSelectPanel &&
                        <BankSelectPanel
                            selectKey={data.id}
                            brandId={data.brandId}
                            tradeMethodId={data.tradeMethodId}
                            currency={data.currency}
                            onCancel={this.onCloseBankSelectPanel}
                            onSelect={this.onSelectAddedBank} />
                }
                {
                    this.state.showSaleOrderPanel &&
                        <SaleOrderPanel
                            selectKey={data.id}
                            brandId={data.brandId}
                            dealerId={data.dealerId}
                            currency={data.currency}
                            tradeMethodId={data.tradeMethodId}
                            paymentType={data.paymentType}
                            transportType={data.deliveryTerms}
                            salesOrderPriceTerms={data.salesOrderPriceTerms}
                            tradeMethods={this.props.initEnum.tradeMethods}
                            onCancel={this.onCloseSaleOrderPanel}
                            onSelect={this.onSelectSaleOrder} />
                }
                {
                    this.state.showSaleOrderDetailPanel &&
                        <SaleOrderDetailPanel
                            selectKey={data.id}
                            saleOrderId={data.saleOrderId}
                            currentSelectRowkeys={details}
                            onCancel={this.onCloseSaleOrderDetailPanel}
                            onSelect={this.onSelectAddedSaleOrderDetail} />
                }
                {
                    this.state.showKdClaimPanel &&
                        <KdClaimPanel
                            selectKey={data.id}
                            brandId={data.brandId}
                            dealerId={data.dealerId}
                            onCancel={this.onCloseKdClaimPanel}
                            onSelect={this.onSelectKdClaim} />
                }
                {
                    this.state.showImportPanel &&
                    <ImportPanel
                        dealerId={this.props.id}
                        onCancel={this.onCloseImportPanel}
                        onImportChange={this.onImportChange} />
                }
                {
                    this.state.showPartImportPanel &&
                    <ImportPartPanel
                        dealerId={this.props.id}
                        onCancel={this.onClosePartImportPanel}
                        onImportChange={this.onPartImportChange} />
                }
            </div>
        );
    }
}

NewPanel.propTypes = {
    initEnum: PropTypes.object.isRequired,
    onCancel: PropTypes.func.isRequired,
    onSubmit: PropTypes.func.isRequired,
    history: PropTypes.object,
    intl: PropTypes.object,
    pagePermission: PropTypes.array,
};
import {connect} from 'react-redux';
import {
    onSubmit,
    tableSearch,
} from './actions';
import {selectorFactory} from 'Shared/utils/immutableToJsSelectorFactory';
import {createSelector} from 'reselect';
const getPagePermission = selectorFactory(['page', 'domainData', 'permissions', 'data']);
const getinitEnumData = createSelector(
    state => state.getIn(['page', 'domainData', 'initData']),
    init => {
        const initData = init.toJS();
        const brands = initData.brands ? initData.brands.map(item => ({
            text: `${'('}${item.code}${')'}${item.name}`,
            value: item.id
        })) : [];
        const tradeMethods = initData.tradeMethods ? initData.tradeMethods.map(item => ({
            text: `${'('}${item.code}${')'}${item.name}`,
            value: item.id
        })) : [];
        const carriers = initData.carriers ? initData.carriers.map(item => ({
            text: `${'('}${item.code}${')'}${item.name}`,
            value: item.id
        })) : [];
        const shippingPorts = initData.shippingPorts ? initData.shippingPorts.map(item => ({
            text: `${'('}${item.code}${')'}${item.name}`,
            value: item.id
        })) : [];
        return {
            brands,
            tradeMethods,
            carriers,
            shippingPorts
        };
    }
);
const mapStateToProps = state => ({
    pagePermission: getPagePermission(state),
    initEnum: getinitEnumData(state),
});

const mapDispatchToProps = (dispatch, props) => {
    const ownProps = {
        onSubmit: (data, details, saleProformaPartDetails) => dispatch(onSubmit(data, details, saleProformaPartDetails)).then(result => {
            if(result.success) {
                dispatch(tableSearch());
                props.history.push(routes.query.url());
            }
        }),
        onCancel: () => props.history.push(routes.query.url()),
    };
    return ownProps;
};

export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(NewPanel));
